package com.zjxf.config;

import com.jagregory.shiro.freemarker.ShiroTags;
import com.zjxf.tags.HasAnyPermissionsTag;
import com.zjxf.tags.LacksAnyPermissionsTag;
import freemarker.template.Configuration;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

/**
 * 使FreeMarker支持Shiro标签
 * @author wqkeep
 */
@Component
public class ShiroTagFreeMarkerConfigure implements InitializingBean {

    @Autowired
    private Configuration configuration;

    @Autowired
    private FreeMarkerViewResolver resolver;

    @Override
    public void afterPropertiesSet() {
        ShiroTags tags = new ShiroTags();
        tags.put("hasAnyPermissions", new HasAnyPermissionsTag());
        tags.put("lacksAnyPermissions", new LacksAnyPermissionsTag());
        configuration.setSharedVariable("shiro", tags);
        resolver.setRequestContextAttribute("context");
    }
}